import type { CommonResponseData } from '@/api/user/type'
import request from '@/utils/request'
import type { SkuData, SpuData } from './type'
import type { PageData } from '../treadmark/types'
import { el } from 'element-plus/es/locales.mjs'

const enum Api {
  SPU_PAGE = '/spu/list',
  SPU_ADD = '/spu/add',
  SPU_EDIT = '/spu/edit',
  SPU_DELETE = '/spu/delete',
  SKU_PAGE = '/sku/list',
  SKU_ADD = '/sku/add',
}

export const reqSpuPage = (pageNo: number, pageSize: number, attrId: number) =>
  request.get<any, CommonResponseData<PageData<SpuData>>>(
    Api.SPU_PAGE +
      '?pageNo=' +
      pageNo +
      '&pageSize=' +
      pageSize +
      '&attrId=' +
      attrId
  )

export const reqSaveSpu = (spuData: SpuData) => {
  if (spuData.id) {
    return request.post<any, CommonResponseData<boolean>>(Api.SPU_EDIT, spuData)
  } else {
    return request.post<any, CommonResponseData<boolean>>(Api.SPU_ADD, spuData)
  }
}
export const reqSaveSku = (skuData: SkuData) =>
  request.post<any, CommonResponseData<boolean>>(Api.SKU_ADD, skuData)
